/*
包名称：用户 满意度调查
关联模板：myddc.html
*/
package controllers

import (
	"strings"
	"xmgl/models"

	"time"

	"github.com/astaxie/beego"
)

type MyddcController struct {
	beego.Controller
}
type MyddcOkController struct {
	beego.Controller
}

func (this *MyddcController) Get() {
	var (
		dclb models.Stu_Myddc
		err  error
	)
	err = dclb.GetDcLb()
	if err != nil {

	}
	this.Data["DCLBS"] = dclb.Lbs //取得调查类型的列表，切片类型
	this.TplName = "myddc.html"
}

func (this *MyddcController) Post() {
	//收到ajax数据后，返回结构体的json数据，有二种做法都是可以的
	type myddcOk struct {
		Url       string
		RetType   string
		RetString string
		GoUrl     string
	}
	var (
		ip_addr string
		//port    string
		myddc models.Stu_Myddc
		err   error
	/*tmp   myddcOk
	json1 []byte
	err   error*/
	)
	//err = this.Ctx.Request.PostForm()
	t := time.Now()

	ip_addr = strings.Split(this.Ctx.Request.RemoteAddr, ":")[0]
	//port = strings.Split(this.Ctx.Request.RemoteAddr, ":")[1]
	//log.Println("IP:", ip_addr, "\n port:", port)

	myddc.Ip = ip_addr
	myddc.Gh = ""
	myddc.Dd = ""
	myddc.Sj = t.Format("2006-01-02 15:04:05")
	myddc.FormValues = this.Ctx.Request.PostForm
	err = myddc.SaveDcb()
	if err != nil {
		this.Redirect("/wwfw/myddc", 302)
		return
	}
	this.Redirect("/wwfw/myddcok", 302)
	/*不使用JSON输出，而是直接跳转
	id := this.GetString("id")
	data := this.GetString("data")
	log.Println("myddc.html 接收到ajax数据,id:", id, "\tdata:", data)
	tmp = myddcOk{Url: "myddc", RetType: "myddy", RetString: "ok", GoUrl: "/myddcok"}

	//用go的标准库输出json数据
	json1, _ = json.Marshal(tmp)
	io.WriteString(this.Ctx.ResponseWriter, string(json1[:]))

	//beego的搞法，直接返回json数据
	//this.Data["json"] = &tmp
	//this.ServeJSON()
	*/

}

func (this *MyddcOkController) Get() {
	this.TplName = "myddcok.html"
}
